| Conditions | 6 |
| Paths | 3 |
| Total Lines | 57 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | var valName = 1; |
||
| 59 | function registerCheck() { |
||
| 60 | var name = $("#name").val(); |
||
| 61 | var email = $("#email").val(); |
||
| 62 | var username = $("#username").val(); |
||
| 63 | var mob = $("#mob").val(); |
||
| 64 | var password = $("#passRegister").val(); |
||
| 65 | |||
| 66 | initRegister(); |
||
| 67 | |||
| 68 | if(valName === 0 && valEmail === 0 && valUser === 0 && valMob === 0 && valPassRegister === 0) |
||
| 69 | { |
||
| 70 | var q = {"name":name,"email":email,"username":username,"mob":mob,"password":password}; |
||
| 71 | q = "q=" + JSON.stringify(q); |
||
| 72 | // console.log(q); |
||
| 73 | var xmlhttp = new XMLHttpRequest(); |
||
|
|
|||
| 74 | xmlhttp.onreadystatechange = function() |
||
| 75 | { |
||
| 76 | if (xmlhttp.readyState == 4 && xmlhttp.status == 200) |
||
| 77 | { |
||
| 78 | var result = JSON.parse(xmlhttp.responseText); |
||
| 79 | // console.log(result); |
||
| 80 | if(result['location']) |
||
| 81 | { |
||
| 82 | location.href = result['location']; |
||
| 83 | } |
||
| 84 | if(result['name']) |
||
| 85 | { |
||
| 86 | showNameError(result['name']); |
||
| 87 | } |
||
| 88 | if(result['password']) |
||
| 89 | { |
||
| 90 | showPassErrorRegister(result['password']); |
||
| 91 | } |
||
| 92 | if(result['email']) |
||
| 93 | { |
||
| 94 | showEmailError(result['email']); |
||
| 95 | } |
||
| 96 | if(result['username']) |
||
| 97 | { |
||
| 98 | showUsernameError(result['username']); |
||
| 99 | } |
||
| 100 | if(result['mob']) |
||
| 101 | { |
||
| 102 | showMobError(result['mob']); |
||
| 103 | } |
||
| 104 | } |
||
| 105 | }; |
||
| 106 | xmlhttp.open("POST", "ajax/validate_register.php", true); |
||
| 107 | xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); |
||
| 108 | xmlhttp.send(q); |
||
| 109 | } |
||
| 110 | else |
||
| 111 | { |
||
| 112 | // alert("Please Fill correct details"); |
||
| 113 | $("#myModal").modal() |
||
| 114 | } |
||
| 115 | } |
||
| 116 | |||
| 259 | } |
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.